<template>
  <div>
    <div class="blockLeft"><span class="aSpan">{{ptitle}}</span></div>
    <div class="blockRightLong">
      <span v-if="preadonly" class="aSpan">{{realValue}}</span>
      <textarea v-else class="textarea"
                draggable="false"
                @input="inputAction"
                @change="changeAction"
                v-model="realValue">
      </textarea>
    </div>
  </div>
</template>

<script>
export default {
  name: 'bpmCBlockTextarea',
  model: {
    prop: 'pcontent',
    event: 'changed'
  },
  props: {
    show: {
      type: Boolean,
      default: true
    },
    // 只读/可编辑,
    preadonly: {
      type: Boolean,
      default: false
    },
    ptitle: {
      type: String,
      default: ' '
    },
    pcontent: {
      type: String,
      default: ' '
    },
    validateExp: {
      type: Object,
      default () {
        return {}
      }
    }
  },
  data: function () {
    return {
      realValue: this.pcontent
    }
  },
  watch: {
    pcontent (to) {
      this.realValue = to
    }
  },
  methods: {
    inputAction (event) {
      // console.log(event, this.realValue)
      if (!this.validateExp || !this.validateExp.flag) return
      if (this.validateExp.maxlength && this.validateExp.maxlength > 0) {
        this.realValue = this.realValue.slice(0, this.validateExp.maxlength)
      }
    },
    changeAction () {
      // console.log(event)
      this.$emit('changed', this.realValue)
      this.$emit('valueChanged', this.realValue)
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  .blockLeft {
    background-color: #f4f4f4;
    float: left;
    text-align: center;
    width: 140px;
    min-height: 58px;
    border-left: 1px solid #e3e3e3;
    border-right: 1px solid #e3e3e3;
  }
  .blockRightLong {
    background-color: #eff3f6;
    float: left;
    padding-left: 8px;
    min-height: 58px;
    width: 830px;
    min-width: 830px;
    text-align: left;
  }
  .aSpan {
    display: block;
    margin-top: 4px;
  }
  .textarea {
     min-width: 800px;
     height: 40px;
     margin: 3px 30px 3px 0px;
     font: 13px Arial;
   }
</style>
